/**
 * this file use to handle request from client
 * 
 */

$(document).ready(function() {

	var define = new Define();
	var date = new Date();

	/**
	 * when user click 「Enter」 key 1. send request to server 2.get response from
	 * server 3. show revived message
	 */
	$(".chatbox-txt").on("keypress", function(event) {
		var code = event.keyCode;
		if (code == 13) {// when user press [enter] key
			/*
			 * send message to server using ajax
			 */
			var data = {};
			// set value for data variable
			data.subject = define.SUBJECT_MSG;
			data.content = $(this).val();
			data.time = date.getTime();
			// console.log(data);
			// // set value for message object
			// var msg = new Message();
			// msg.init(data);
			//
			// // set value for chatuser object
			//
			// var ChatUser = (function(my) {
			// return my;
			// }(ChatUser || {}));
			// // ChatUser.setUsername("admin");
			var controller = new ChatController();
			// controller.init(ChatUser, msg);
			var url = "/comunication/chats";
			var type = "POST";
			var dataType = "JSON";
			controller.sendData(url, type, dataType, define.SEND_MSG, data);
		}
	});
	/**
	 * When scroll scroll bar then load old message
	 */
	$(document).on(".", "", function(event) {
	});
});